#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int n;
int sa[N],rk[N];
int df[N],dg[N];
int fa[N],mx[N];
char s[N];
vector<int> adj[N];
bool solve(){
    for(int i=1;i<=n;i++){
        if(sa[i]<1||sa[i]>n)return 0;
        rk[i]=0;
        fa[i]=i;
        mx[i]=0;
        adj[i].clear();
    }
    for(int i=1;i<=n;i++)rk[sa[i]]=i;
    for(int i=1;i<=n;i++)if(!rk[i])return 0;
    rk[n+1]=0;
    for(int i=1,j=0;i<=n;i++){
        if(df[i]%2==0)return 0;
        int l=i-df[i]/2,r=i+df[i]/2;
        if(l<1||r>n)return 0;
        while(j<r){
            j++;
            fa[j]=fa[i+i-j];
        }
        if(l>1&&r<n)adj[max(rk[l-1],rk[r+1])].push_back(min(rk[l-1],rk[r+1]));
        if(i==n)continue;
        if(dg[i]%2==1)return 0;
        l=i-dg[i]/2+1,r=i+dg[i]/2;
        if(l<1||r>n)return 0;
        while(j<r){
            j++;
            fa[j]=fa[i+i+1-j];
        }
        if(l>1&&r<n)adj[max(rk[l-1],rk[r+1])].push_back(min(rk[l-1],rk[r+1]));
    }
    for(int i=1;i<=n;i++)mx[fa[i]]=max(mx[fa[i]],rk[i]);
    for(int i=1;i<=n;i++)mx[i]=mx[fa[i]];
    int l=0,r=0;
    while(r<n){
        l=r+1;
        r=l;
        for(int i=l;i<=r;i++)r=max(r,mx[sa[i]]);
        for(int i=l+1;i<=r;i++)if(rk[sa[i-1]+1]>rk[sa[i]+1])return 0;
        if(l==1)s[l]='a';
        else s[l]=s[l-1];
        for(int i=l;i<=r;i++){
            for(int j:adj[i]){
                if(j>=l)return 0;
                if(s[j]==s[l])s[l]++;
            }
        }
        if(l>1&&s[l]==s[l-1]&&rk[sa[l-1]+1]>rk[sa[l]+1])s[l]++;
        for(int i=l+1;i<=r;i++)s[i]=s[l];
    }
    return 1;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>sa[i];
            sa[i]++;
        }
        for(int i=1;i<n;i++)cin>>df[i]>>dg[i];
        cin>>df[n];
        if(solve())for(int i=1;i<=n;i++)cout<<s[rk[i]];
        else cout<<-1;
        cout<<'\n';
    }
    return 0;
}
